<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>es8的特性</title>
</head>
<body>
  
  <h1 class="card"></h1>


  <script>
    //对象的相关操作
    const obj = {
      name: "why",
      age: 18,
      height: 1.88,
      address: "广州市"
    }

    // 1.获取所有的key
    const keys = Object.keys(obj)
    console.log(keys)

    // 2.ES8 Object.values
    const values = Object.values(obj)
    console.log(values)

    // 3.ES8 Object.entries
    // 3.1. 对对象操作
    const entries = Object.entries(obj)
    console.log(entries)
    for (const entry of entries) {
      console.log(entry)
    }

      // 3.2. 对数组/字符串操作(了解)
    console.log(Object.entries("123")) 

    //字符串填充方法
    // padStart和padEnd
    // 1.应用场景一: 对时间进行格式化
    // const minute = "15".padStart(2, "0")
    // const second = "6".padStart(2, "0")

    // console.log(`${minute}:${second}`)
    
    // 2.应用场景二: 对一些敏感数据格式化
    let cardNumber = "132666200001018899"
    const sliceNumber = cardNumber.slice(-4)
    cardNumber = sliceNumber.padStart(cardNumber.length, "*")
    const cardEl = document.querySelector(".card")
    cardEl.textContent = cardNumber


  </script>
</body>
</html>